package com.biyao.service.model.base.imp;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import java.util.HashMap;
import java.util.Map;

import com.biyao.schedulingdao.base.TRollerBasicMapper;
import com.biyao.schedulingentity.base.TGrindWheelBasicEntity;
import com.biyao.schedulingentity.base.TRollerBasicEntity;
import com.biyao.schedulingentity.base.TRollerRacksEntity;
import com.biyao.service.model.base.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.ArrayList;
/**
 * 
 *
 * @author code generator
 * @date 2019-09-16 09:44:11
 */
@Service
public class TRollerBasicService extends ServiceImpl<TRollerBasicMapper, TRollerBasicEntity> implements TRollerBasicMessage {

    @Autowired
    private TRollerTypeMessage tRollerTypeMessage;
    @Autowired
    private TRollerMaterialMessage tRollerMaterialMessage;
    @Autowired
    private TGrinderMessage tGrinderMessage;
    @Autowired
    private TBearingBoxMessage tBearingBoxMessage;

    public Page list(int pageNum, int pageSize){

        EntityWrapper<TRollerBasicEntity> tRollerBasicentityWrapper=new EntityWrapper<>();
        Page page=selectPage(new Page(pageNum,pageSize),tRollerBasicentityWrapper);
        page.setRecords(formatRecords(page.getRecords()));
        return page;
    }
    public Page searchListByCode(String code){
        EntityWrapper<TRollerBasicEntity> tRollerBasicentityWrapper=new EntityWrapper<>();
        tRollerBasicentityWrapper.like("code",code+"%");
        Page page=selectPage(new Page(1,100),tRollerBasicentityWrapper);
        page.setRecords(formatRecords(page.getRecords()));
        return page;
    }
    List formatRecords(List<TRollerBasicEntity> list){
        List resList=new ArrayList();
        for(TRollerBasicEntity tRollerBasicEntity:list){
            Map map=formatEntity(tRollerBasicEntity);
            resList.add(map);
        }
        return resList;
    }

    Map formatEntity(TRollerBasicEntity tRollerBasicEntity){
        Map map=new HashMap(16);
        //轧辊信息
        if(tRollerBasicEntity.getId()!=null){
           map.put("id",tRollerBasicEntity.getId());
        }
        //轧辊编号
        if(tRollerBasicEntity.getCode()!=null){
           map.put("code",tRollerBasicEntity.getCode());
        }
        //顺序号
        if(tRollerBasicEntity.getSequence()!=null){
           map.put("sequence",tRollerBasicEntity.getSequence());
        }
        //t_roller_type.id
        if(tRollerBasicEntity.getTypeId()!=null){
           map.put("typeId",tRollerBasicEntity.getTypeId());
           if(tRollerTypeMessage.selectTRollerTypeById(tRollerBasicEntity.getTypeId())!=null){
               map.put("typeCode",tRollerTypeMessage.selectTRollerTypeById(tRollerBasicEntity.getTypeId()).getCode());
           }
        }
        //t_roller_matertial.id
        if(tRollerBasicEntity.getMaterialId()!=null){
           map.put("materialId",tRollerBasicEntity.getMaterialId());
           if(tRollerMaterialMessage.selectRollerMaterialEntityById(tRollerBasicEntity.getMaterialId())!=null){
               map.put("materialCode",tRollerMaterialMessage.selectRollerMaterialEntityById(tRollerBasicEntity.getMaterialId()).getCode());
           }
        }
        if(tRollerBasicEntity.getGrinderId()!=null){
            map.put("grinderId",tRollerBasicEntity.getGrinderId());
            if(tGrinderMessage.selectEntryById(tRollerBasicEntity.getGrinderId())!=null){
                map.put("grinderCode", tGrinderMessage.selectEntryById(tRollerBasicEntity.getGrinderId()).getCode());
            }
        }
        //辊架类型
        if(tRollerBasicEntity.getRackType()!=null){
           map.put("rackType",tRollerBasicEntity.getRackType());
        }
        //初始直径
        if(tRollerBasicEntity.getOriginalDiameter()!=null){
           map.put("originalDiameter",tRollerBasicEntity.getOriginalDiameter());
        }
        //报废直径
        if(tRollerBasicEntity.getDiscardDiameter()!=null){
           map.put("discardDiameter",tRollerBasicEntity.getDiscardDiameter());
        }
        if(tRollerBasicEntity.getPrecision()!=null){
            map.put("precision",tRollerBasicEntity.getPrecision());
        }
        if(tRollerBasicEntity.getRoughness()!=null){
            map.put("roughness",tRollerBasicEntity.getRoughness());

        }
        //轧辊状态
        if(tRollerBasicEntity.getState()!=null){
           map.put("state",tRollerBasicEntity.getState());
        }
        //生产厂家
        if(tRollerBasicEntity.getManufacturer()!=null){
           map.put("manufacturer",tRollerBasicEntity.getManufacturer());
        }
        //生产日期
        if(tRollerBasicEntity.getManufactureDate()!=null){
           map.put("manufactureDate",tRollerBasicEntity.getManufactureDate());
        }
         //信号量
        if(tRollerBasicEntity.getSemaphore()!=null){
            map.put("semaphore",tRollerBasicEntity.getSemaphore());
        }
        //
        if(tRollerBasicEntity.getCreateTime()!=null){
           map.put("createTime",tRollerBasicEntity.getCreateTime());
        }
        //
        if(tRollerBasicEntity.getUpdateTime()!=null){
           map.put("updateTime",tRollerBasicEntity.getUpdateTime());
        }
        //
        if(tRollerBasicEntity.getCreateBy()!=null){
           map.put("createBy",tRollerBasicEntity.getCreateBy());
        }
        //
        if(tRollerBasicEntity.getUpdateBy()!=null){
           map.put("updateBy",tRollerBasicEntity.getUpdateBy());
        }
        if(tRollerBasicEntity.getApplyFram()!=null){
            map.put("applyFram",tRollerBasicEntity.getApplyFram());
        }
        if(tRollerBasicEntity.getCorrFram()!=null){
            map.put("corrFram",tRollerBasicEntity.getCorrFram());
        }
        if(tRollerBasicEntity.getRemark()!=null){
            map.put("remark",tRollerBasicEntity.getRemark());
        }
        if(tRollerBasicEntity.getThickness()!=null){
            map.put("thickness",tRollerBasicEntity.getThickness());
        }
        if(tRollerBasicEntity.getPrice()!=null){
            map.put("price",tRollerBasicEntity.getPrice());
        }
        return map;
    }

    public Boolean selectCodeIsRepeat(String code) {
        EntityWrapper<TRollerBasicEntity> tRollerBasicEntityEntityWrapper=new EntityWrapper<>();
        tRollerBasicEntityEntityWrapper.eq("code",code);
        List<TRollerBasicEntity> list=selectList(tRollerBasicEntityEntityWrapper);
        if(list.size()>0){
            return true;
        }
        return false;
    }

    public Boolean selectUpdateCodeIsRepeat(String code,Integer id) {
        EntityWrapper<TRollerBasicEntity> tRollerBasicEntityEntityWrapper=new EntityWrapper<>();
        tRollerBasicEntityEntityWrapper.eq("code",code);
        List<TRollerBasicEntity> list=selectList(tRollerBasicEntityEntityWrapper);
        if(list.size()>0){
            if(list.get(0).getId().intValue()!=id.intValue()){
                return true;
            }
            return false;
        }
        return false;
    }

    @Override
    public Float selectRollerBasicDiameter(Integer id) {
        return selectById(id).getOriginalDiameter();
    }

    @Override
    public TRollerBasicEntity selectRollerBasicById(Integer id) {
        return selectById(id);
    }

    @Override
    public List<Map> selectRollerBasicList() {
        EntityWrapper<TRollerBasicEntity> tRollerBasicentityWrapper=new EntityWrapper<>();
        return formatRecords(selectList(tRollerBasicentityWrapper));
    }
}

